<?php
require_once("../../controllers/init.php");
//echo "Filesystem root = ".$FILE_SYSTEM_ROOT."\n<br>";
require_once($FILE_SYSTEM_ROOT."/controllers/authentication.php");
//echo "logged on - ".(($IS_LOGGED_ON)?"true\n":"false\n");
require_once($FILE_SYSTEM_ROOT."/model/classes/events/EventsResultSet.php");

$today = new DateTime("now");

$date=new DateTime($_GET['date']);
$month=$date->format("F");
$year=$date->format("Y");
$cell = array();
$cellClass = array();

// find first day of month
$date1=new DateTime($date->format("Y-m-01"));
//find first day of row
$offset=$date1->format("N")-1;
$date1->modify('-'.$offset.' day');

for($i=0;$i<35;$i++)
	{

		$date2=new DateTime($date1->format("Y-m-d"));
		$date2->modify('+'.$i.' day');
		$date3=new DateTime($date2->format("Y-m-d"));
		$date3->modify("+1 day");
		
		$events=new EventsResultSet();
		$events->setFrom($date2);
		$events->setTo($date3);
		
		$dayEventsHTML="";
		foreach($events->getEvents() as $event)
		{
			$timeString = $event->getStart()->format("H:i")."-".$event->getEnd()->format("H:i");
			if($timeString=="00:00-00:00")$timeString="All day";
			$dayEventsHTML.="<div class=\"calendar-month-event-container\"><div class=\"calendar-month-event\" id=\"calendar-month-event-".$event->getEventID()."\">"
				."<span class=\"calendar-month-event-time\">".$timeString."</span>"
				."<span class=\"calendar-month-event-title\">".$event->getTitle()."</span></div></div>";
		}
		$cellClass[$i] = ($date2->format("Y-m-d")==$today->format("Y-m-d"))?"calendar-month-cell calendar-month-cell-today":"calendar-month-cell";
		
		$cell[$i]="<div id=\"calendar-month-date-".$i."\" class=\"calendar-month-date\"><input type=\"hidden\" id=\"calendar-month-date-fulldate-".$i."\" value=\"".$date2->format("Y-m-d")."\" />".$date2->format("j")."</div>\n";
		$cell[$i].=$dayEventsHTML;
	}
	



?>
		<div id="calendar-month-event-view"></div>
		<div id="calendar-month-event-edit"></div>
		<div id="calendar-month-event-edit-booking-edit">
			<div id="calendar-month-event-edit-booking-edit-tabs"></div>
		</div>
		<div class="calendar-month-row">
			<div class="calendar-month-cell-title" id="calendar-month-title-1">Monday</div>
			<div class="calendar-month-cell-title" id="calendar-month-title-2">Tuesday</div>
			<div class="calendar-month-cell-title" id="calendar-month-title-3">Wednesday</div>
			<div class="calendar-month-cell-title" id="calendar-month-title-4">Thursday</div>
			<div class="calendar-month-cell-title" id="calendar-month-title-5">Friday</div>
			<div class="calendar-month-cell-title" id="calendar-month-title-6">Saturday</div>
			<div class="calendar-month-cell-title" id="calendar-month-title-7">Sunday</div>
		</div>
		<div class="calendar-month-row">
			<div class="<?php echo $cellClass[0];?>" id="calendar-month-cell-00"><?php echo $cell[0];?></div>
			<div class="<?php echo $cellClass[1];?>" id="calendar-month-cell-01"><?php echo $cell[1];?></div>
			<div class="<?php echo $cellClass[2];?>" id="calendar-month-cell-02"><?php echo $cell[2];?></div>
			<div class="<?php echo $cellClass[3];?>" id="calendar-month-cell-03"><?php echo $cell[3];?></div>
			<div class="<?php echo $cellClass[4];?>" id="calendar-month-cell-04"><?php echo $cell[4];?></div>
			<div class="<?php echo $cellClass[5];?>" id="calendar-month-cell-05"><?php echo $cell[5];?></div>
			<div class="<?php echo $cellClass[6];?>" id="calendar-month-cell-06"><?php echo $cell[6];?></div>
		</div>
		<div class="calendar-month-row">
			<div class="<?php echo $cellClass[7];?>" id="calendar-month-cell-10"><?php echo $cell[7];?></div>
			<div class="<?php echo $cellClass[8];?>" id="calendar-month-cell-11"><?php echo $cell[8];?></div>
			<div class="<?php echo $cellClass[9];?>" id="calendar-month-cell-12"><?php echo $cell[9];?></div>
			<div class="<?php echo $cellClass[10];?>" id="calendar-month-cell-13"><?php echo $cell[10];?></div>
			<div class="<?php echo $cellClass[11];?>" id="calendar-month-cell-14"><?php echo $cell[11];?></div>
			<div class="<?php echo $cellClass[12];?>" id="calendar-month-cell-15"><?php echo $cell[12];?></div>
			<div class="<?php echo $cellClass[13];?>" id="calendar-month-cell-16"><?php echo $cell[13];?></div>
		</div>
		<div class="calendar-month-row">
			<div class="<?php echo $cellClass[14];?>" id="calendar-month-cell-20"><?php echo $cell[14];?> </div>
			<div class="<?php echo $cellClass[15];?>" id="calendar-month-cell-21"><?php echo $cell[15];?></div>
			<div class="<?php echo $cellClass[16];?>" id="calendar-month-cell-22"><?php echo $cell[16];?></div>
			<div class="<?php echo $cellClass[17];?>" id="calendar-month-cell-23"><?php echo $cell[17];?></div>
			<div class="<?php echo $cellClass[18];?>" id="calendar-month-cell-24"><?php echo $cell[18];?></div>
			<div class="<?php echo $cellClass[19];?>" id="calendar-month-cell-25"><?php echo $cell[19];?></div>
			<div class="<?php echo $cellClass[20];?>" id="calendar-month-cell-26"><?php echo $cell[20];?></div>
		</div>
		<div class="calendar-month-row">
			<div class="<?php echo $cellClass[21];?>" id="calendar-month-cell-30"><?php echo $cell[21];?></div>
			<div class="<?php echo $cellClass[22];?>" id="calendar-month-cell-31"><?php echo $cell[22];?></div>
			<div class="<?php echo $cellClass[23];?>" id="calendar-month-cell-32"><?php echo $cell[23];?></div>
			<div class="<?php echo $cellClass[24];?>" id="calendar-month-cell-33"><?php echo $cell[24];?></div>
			<div class="<?php echo $cellClass[25];?>" id="calendar-month-cell-34"><?php echo $cell[25];?></div>
			<div class="<?php echo $cellClass[26];?>" id="calendar-month-cell-35"><?php echo $cell[26];?></div>
			<div class="<?php echo $cellClass[27];?>" id="calendar-month-cell-36"><?php echo $cell[27];?></div>
		</div>
		<div class="calendar-month-row">
			<div class="<?php echo $cellClass[28];?>" id="calendar-month-cell-46"><?php echo $cell[28];?></div>
			<div class="<?php echo $cellClass[29];?>" id="calendar-month-cell-40"><?php echo $cell[29];?></div>
			<div class="<?php echo $cellClass[30];?>" id="calendar-month-cell-41"><?php echo $cell[30];?></div>
			<div class="<?php echo $cellClass[31];?>" id="calendar-month-cell-42"><?php echo $cell[31];?></div>
			<div class="<?php echo $cellClass[32];?>" id="calendar-month-cell-43"><?php echo $cell[32];?></div>
			<div class="<?php echo $cellClass[33];?>" id="calendar-month-cell-44"><?php echo $cell[33];?></div>
			<div class="<?php echo $cellClass[34];?>" id="calendar-month-cell-45"><?php echo $cell[34];?></div>
		</div>

